package com.zyz.N_反射机制.基本应用.读取注解信息;

import java.lang.reflect.Field;

/**
 * @author: vick
 * @Date: 2025/4/17
 * @Description:
 * @version: 1.0
 */
public class Test {
    public static void main(String[] args) throws ClassNotFoundException {
        Class userClass = Class.forName("com.vick.N_反射机制.基本应用.读取注解信息.User");
        //获取类上的，直接 class.getAnnotation
        Table tableannotation = (Table) userClass.getAnnotation(Table.class);
        String tableName = "";
        if (tableannotation != null) {
            tableName = tableannotation.value();
        }
        System.out.println(tableannotation);
        //获取属性上的注解
        Field[] declaredFields = userClass.getDeclaredFields();
        for (Field field : declaredFields) {
            Column column = field.getAnnotation(Column.class);
            if (column != null) {
                System.out.println(column);
            }
        }
    }
}
